package com.jian.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jian.common.ErrorCode;
import com.jian.domain.Entrust;
import com.jian.exception.BusinessException;
import com.jian.mapper.EntrustMapper;
import com.jian.service.EntrustService;

import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
* @author HB_龙
* @description 针对表【entrust(用户表id)】的数据库操作Service实现
* @createDate 2022-06-11 15:31:20
*/
@Service
public class EntrustServiceImpl extends ServiceImpl<EntrustMapper, Entrust>
    implements EntrustService {

    private final static int origin_pay = 0;
    private SimpleDateFormat sdf;

    @Override
    public long getMoney(int id) {
        //日期格式转换器
        sdf = new SimpleDateFormat("yyyy-MM-dd:HH-mm");
        //当前时间
        String nowday = sdf.format(new Date());
        //获取对应表数据
        Entrust result = getById(id);
        if(result != null)
        {

            String update = sdf.format(result.getUpdateTime());

            return detime(new Date(),result.getUpdateTime());
        }
        else {
//            System.out.println("NULL ..");
            throw new BusinessException(ErrorCode.PARAM_NULL_ERROR,"找不到对象");
        }
//        return 0;
    }

    public long detime(Date n,Date u)
    {
        long ntimestamp = n.getTime() ;
        long utimestamp = u.getTime() ;
        System.out.println("ans =   " + ntimestamp + "  " + utimestamp);

        if(((ntimestamp - utimestamp) / (1000 * 3600) ) - 8 < 24 ) {
            return 0;
        }
        else {
            return (ntimestamp - utimestamp) / (1000 * 3600 *24);
        }
//        System.out.println((ntimestamp - utimestamp) / (1000 * 3600 * 24));
//        return 0;
    }

}




